require.config({
    paths: {
        u: '../../utils'
    }
});

require([
     'u/common/app',
	 'u/libs/iscroll5',
	 'u/com/readmore',
	 'u/com/tab_load_more',
	 'u/libs/play',
	
], function() {
  $(function(){
	  var myScroll;
	function loaded() {
		myScroll = new IScroll('#menu_con', {eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false });
	}
	 function init(){
			$("img[lazyload]").scrollLoading()
	}
	init();
	readmore();
	function readmore(){
		$('[show_more]').readmore({
			   moreLink: '<a class="more" href="javascript:;">点击展开<i class="hm_icon a2 cur"></i></a>',
			   lessLink: '<a class="more" href="javascript:;">点击收起<i class="hm_icon a2 "></i></a>',
			   maxHeight: 50,
			   afterToggle: function(trigger, element, expanded) {
				  if(! expanded) {
					 $('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } );
				  }
				}
	   });
	}
	$(".menu_con em").each(function(index, element) {
		 var T=$(this);
		 T.click(function(){
			myScroll.scrollToElement($('#menu_con em').eq($(".menu_con em").index(this))[0],1000, -($(this).width()+30), true)
			return false
		 })
			
	});
	//如果是video.list
	if($("#menu_con").length>0){
	   loaded();
	   var tab_load_more_obj=new tab_load_more({
			 ele:"#menu_con",
			 tabli:"em",
			 current:"em.cur",
			 box:".video_nr",
			 boxcur:".video_nr.cur ul",
			 success:function(e,page){
				  var Data=e.html;
				  var timer=null;
				  $(".lm_load_more").show()
				  timer=setTimeout(function(){
					  clearTimeout(timer)
					   if (e.hasMore == false) {
						 $(tab_load_more_obj.current).attr("data-page",0)
						 $(Data).appendTo(this.boxcur);
						 $(".lm_load_more").hide()
					} 
					else 
					{
						 $(this.current).attr("data-page",parseInt(page)+1)
						 $(Data).appendTo(this.boxcur);
						
					}
				   init();
				  }.bind(this),500)
				
			 }
		})
	}
  })
})
